﻿namespace ClassyBlog.DomainObjects.Specs.Unit
{
    using System;

    using Machine.Specifications;

    [Subject(typeof(Category))]
    public class when_category_is_created
    {
        static Category category;

        Because of = () => category = new Category();

        It should_have_id = () => category.Id.ShouldNotEqual(Guid.Empty);

        It should_have_empty_children = () =>
            category.Children.ShouldBeEmpty();
    }

    [Subject(typeof(Category))]
    public class when_category_id_is_set
    {
        static Category category;
        static Guid id;

        Establish context = () =>
        {
            category = new Category();
            id = Guid.NewGuid();
        };

        Because of = () => category.Id = id;

        It should_return_the_same = () => category.Id.ShouldEqual(id);
    }

    [Subject(typeof(Category))]
    public class when_parsed_with_blank_string
    {
        static Category category;

        Because of = () => category = Category.Parse(null);

        It should_return_null = () => category.ShouldBeNull();
    }

    [Subject(typeof(Category))]
    public class when_parsed_with_one_category
    {
        static Category category;

        Because of = () => category = Category.Parse("/category");

        It should_return_category = () =>
            category.Title.ShouldEqual("category");
    }

    [Subject(typeof(Category))]
    public class when_parsed_with_two_level_deep_category
    {
        static Category category;

        Because of = () => category = Category.Parse("/category/subcategory");

        It should_return_category_with_child_category = () =>
        {
            category.Title.ShouldEqual("subcategory");
            category.Parent.Title.ShouldEqual("category");
        };
    }

    [Subject(typeof(Category))]
    public class when_parsed_with_more_than_two_level_deep_category
    {
        static Category category;

        Because of = () => category =
            Category.Parse("/category/subcategory/grandchild");

        It should_return_category_with_grand_child_category = () =>
        {
            category.Title.ShouldEqual("grandchild");
            category.Parent.Title.ShouldEqual("subcategory");
            category.Parent.Parent.Title.ShouldEqual("category");
        };
    }
}